package day_2022_9_to_12.Day;

import java.util.HashMap;
import java.util.Map;

/**
 * @author haomin
 * @date 2022/09/16 15:10
 **/
public class Day14_2_Num560_SubarraySum {
    class Solution {
        public int subarraySum(int[] nums, int k) {
            Map<Integer, Integer> map = new HashMap<>();
            int sum = 0, ans = 0;
            for(int i = 0; i < nums.length; ++i){
                sum += nums[i];
                ans += map.getOrDefault(sum-k, 0);
                map.put(sum, map.getOrDefault(sum, 0)+1);
            }
            return ans;
        }
    }
}